<template>
	<div>
	<div style="width: 100%;height: 20px;background-color: #ebedf0;"></div>
	<div style="padding: 20px;">
		<transition name="custom-classes-transition" enter-active-class="animated fadeInDown" leave-active-class="animated fadeOutUp" >
			<addsubjectleader 
				:importsubjectid="subjectselect"
				:importsubjectlist="subjectlist"
				v-on:chance="chance" v-if="show"><span>添加科目长</span></addsubjectleader>
		</transition>
		<Row >
	        <Col span="24" style="text-align: left;margin-top:15px;">
	        	<span>科目筛选：</span>
	        	<RadioGroup  v-model="subjectselect" type="button" @on-change="changeselect">
	        		<Radio v-for="item in subjectlist" :key="item.value" :label="item.value">{{item.label}}</Radio>
			       
			    </RadioGroup>
	        </Col>
	        <Spin size="large" fix v-if="subjectlistshow"></Spin>
	    </Row>
	    
	    <Row>
	    	<Col span="12" style="text-align: left;margin-top:15px;">
	        	<span style="font-size: 20px;">科目长列表：</span>
	        </Col>
	        <Col span="12" style="text-align: right;margin-top:15px;font-size: 16px;">
	        	<Button @click="addsubjectleader" type="success" size="small"><i class="iconfont alicon-add1"></i></Button>
	        	<Button @click="delsubjectleader" type="error" size="small"><i class="iconfont alicon-delete"></i></Button>
	        </Col> 
	        
	    </Row>
	    <div style="position: relative;">
		    <Table style="margin-top: 10px;" border ref="selection" :columns="columns4" :data="data1" @on-selection-change="studentselect"></Table>
	        <Spin size="large" fix v-if="tableshow"></Spin>
        </div>
	</div>
	</div>
</template>

<script>
	import api from "@/components/js/Apidomain.js"
	import addsubjectleader from "@/components/performance/basicsetting/Addsubjectleader"
	export default{
		data(){
			return{
				show:false,					//控制添加科目长的面板显示跟隐藏
				subjectlistshow:false,			//科目选择列表的加载中显示隐藏
				tableshow:false,				//表格列表的加载中显示隐藏
				
				selections:"",				//表格的选择合集
				subjectselect:"",				//选择的科目

				subjectlist: [
					{value: '1',label: '语文'},
					{value: '2',label: '数学'},
                    {value: '3',label: '英语'}, 
                    {value: '4',label: '物理'},
					{value: '5',label: '化学'},
                    {value: '6',label: '生物'}, 
                    {value: '7',label: '历史'},
					{value: '8',label: '地理'},
                    {value: '9',label: '政治'}, 
                ],
                columns4: [
                    {type: 'selection',width: 60,align: 'center'},
                    {title: '工号',key: 'teacherNo',align: 'center',},
                    {title: '姓名',key: 'teacherName',align: 'center',},
                    {title: '任课科目',key: 'subject',align: 'center',},
                    {title: '职称',key: 'jobTitle',align: 'center',},
                    
                    
                ],
                data1: [
//                  {id:"4444",teacherNo:"122672013040",teacherName: '张三',subject: '语文',jobTitle: '初一'},
//                  {id:"4234",teacherNo:"122672013040",teacherName: '李四',subject: '语文',jobTitle: '初一'},
//                  {id:"42244",teacherNo:"122672013040",teacherName: '王五',subject: '语文',jobTitle: '初一'},
//                  {id:"4444444",teacherNo:"122672013040",teacherName: '赵六',subject: '语文',jobTitle: '初一'}
                ]
			}
		},
		components:{
			addsubjectleader,
		},
		created(){
			this.getsubjectlist()
		},
		methods:{
			changeselect:function(){
				this.getsubjectleaderlist();
			},
			studentselect:function(selection){
           		this.selections = selection
//         		//console.log(this.selections)
           	},
           	addsubjectleader:function(){
           		this.show = true;
           	},
           	chance:function(){
           		this.show = false;
           		this.getsubjectleaderlist();
           	},
           	//获取科目选择列表
           	getsubjectlist:function(){
           		this.subjectlistshow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getSubjectSelectList';
            	this.$http.post(url, {}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.subjectlist = response.data.data
						
						//第一次页面进来加载第一项
						if(self.subjectlist.length != 0){
							self.subjectselect = self.subjectlist[0].value;
							self.getsubjectleaderlist();;
						}
						
						self.subjectlistshow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.subjectlistshow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00057',
							duration: 10,
							closable: true
						});
						self.subjectlistshow = false;
					});
           	},
           	getsubjectleaderlist:function(){
           		this.tableshow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getSubjectLeaderInfoList';
            	this.$http.post(url, {subjectId:this.subjectselect}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.data1 = response.data.data
						self.tableshow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.tableshow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00058',
							duration: 10,
							closable: true
						});
						self.tableshow = false;
					});
           	},
           	delsubjectleader:function(){
           		let delallid = [];
           		for(let key in this.selections){
           			delallid.push(this.selections[key].id)
           		}
           		if(delallid.length == 0){
           			this.$Message.error({
								content: '请勾选再删除',
								duration: 10,
								closable: true
							});
           			return;
           		}
           		
           		this.$Modal.confirm({
                    title: '确定删除',
                    content: '<p>确定删除这些信息吗</p>',
                    onOk: () => {
		               this.tableshow = true;
		           		var self = this;
		            	let url = api.apidomain+'/tqes/web/tchTeacher/batchDeleteSubjectLeader';
		            	this.$http.post(url, {'ids':delallid}).then(function(response) {
							if(response.data.success == true){
								self.$Message.success({
				                    content: '删除成功',
				                    duration: 10,
				                    closable: true
		               			})
		//						////console.log(response.data.data)
								self.tableshow = false;
								self.getsubjectleaderlist();
								self.selections = [];
				            }else if(response.data.success == false){
				            		self.$Message.error({
										content: response.data.msg,
										duration: 10,
										closable: true
									});	
				            		self.tableshow = false;
				            	}
							})
							.catch(function(error) {
								self.$Message.error({
									content: '系统发生错误：错误码00059',
									duration: 10,
									closable: true
								});
								self.tableshow = false;
							}); 
		                
                    },
                    onCancel: () => {
//                      this.$Message.info('Clicked cancel');
                    }
                });	
           	},
		}
	}
</script>

<style>
</style>